package com.yuandian.api.management.entity;

/**
 * @Description 告警配置相关的枚举实体
 *
 * @Author LSH
 * @Date 2022/11/22 10:07
 */
public class AlarmEnum {

    /**
     * 颗粒度枚举
     */
    public enum ParticleEnum {
        //1分钟
        ONE_MINUTE("1", "1min", "sys_alarm_particle_type", 60, "1分钟"),
        //5分钟
        FIVE_MINUTE("2", "5min", "sys_alarm_particle_type", 300, "5分钟"),
        //10分钟
        TEN_MINUTE("3", "10min", "sys_alarm_particle_type", 600, "10分钟"),
        //30分钟
        THIRTY_MINUTE("4", "30min", "sys_alarm_particle_type", 1800, "30分钟"),
        //1小时
        ONE_HOUR("5", "1h", "sys_alarm_particle_type", 3600, "1小时"),
        //1天
        ONE_DAY("6", "1d", "sys_alarm_particle_type", 86400, "1天");

        /**
         * 对应字典键值
         */
        private String value;

        /**
         * 对应字典标签
         */
        private String label;

        /**
         * 对应字典类型
         */
        private String dictType;

        /**
         * 颗粒度的时间大小,单位秒
         */
        private Integer second;

        /**
         * 名字
         */
        private String name;

        ParticleEnum(String value, String label, String dictType, Integer second, String name) {
            this.value = value;
            this.label = label;
            this.dictType = dictType;
            this.second = second;
            this.name = name;
        }

        public String getValue() {
            return value;
        }

        public String getLabel() {
            return label;
        }

        public String getDictType() {
            return dictType;
        }

        public Integer getSecond() {
            return second;
        }

        public String getName() {
            return name;
        }

        /**
         * 通过value获取颗粒度枚举
         */
        public static ParticleEnum getEnumByValue(String value) {
            for (ParticleEnum particleEnum : ParticleEnum.values()) {
                if (particleEnum.value.equals(value)) {
                    return particleEnum;
                }
            }
            return null;
        }

        /**
         * 通过颗粒度的时间获取颗粒度枚举
         */
        public static ParticleEnum getEnumBySecond(Integer num) {
            for (ParticleEnum particleEnum : ParticleEnum.values()) {
                if (particleEnum.second.intValue() == num.intValue()) {
                    return particleEnum;
                }
            }
            return null;
        }
    }

    /**
     * 指标对象枚举
     */
    public enum IndicatorObjEnum {
        system("1", "系统", "sys_alarm_indicator_obj_type", "busi_sys_req_trend_m", "system_id, system_name"),
        business("2", "业务", "sys_alarm_indicator_obj_type", "busi_detail_stat_m", "business_code, business_name, system_id, system_name"),
        segment("3", "网端", "sys_alarm_indicator_obj_type", "busi_sys_segment_trend_m", "segment_id, segment_name, system_id, system_name"),
        //暂时没此指标对象
//        component("4", "组件", "sys_alarm_indicator_obj_type",  "", ""),
        //暂时没此指标对象
//        step("5", "步骤", "sys_alarm_indicator_obj_type", "", ""),
        ;

        /**
         * 对应字典键值
         */
        private String value;

        /**
         * 对应字典标签
         */
        private String label;

        /**
         * 对应字典类型
         */
        private String dictType;

        /**
         * 对应查询的表名（表名前缀）
         */
        private String tableName;

        /**
         * 分组的条件
         */
        private String groupByCondition;

        IndicatorObjEnum(String value, String label, String dictType, String tableName, String groupByCondition) {
            this.value = value;
            this.label = label;
            this.dictType = dictType;
            this.tableName = tableName;
            this.groupByCondition = groupByCondition;
        }

        public String getValue() {
            return value;
        }

        public String getLabel() {
            return label;
        }

        public String getDictType() {
            return dictType;
        }

        public String getTableName() {
            return tableName;
        }

        public String getGroupByCondition() {
            return groupByCondition;
        }

        /**
         * 通过value获取指标对象枚举
         */
        public static IndicatorObjEnum getEnumByValue(String value) {
            for (IndicatorObjEnum indicatorObjEnum : IndicatorObjEnum.values()) {
                if (indicatorObjEnum.value.equals(value)) {
                    return indicatorObjEnum;
                }
            }
            return null;
        }
    }

    /**
     * 告警维度类型枚举
     */
    public enum DimensionTypeEnum {
        system("SYSTEM", "系统"),
        business("BUSINESS", "业务"),
        segment("SEGMENT", "网端"),
//        component("COMPONENT", "组件"),
//        step("STEP", "步骤"),
        ;
        private String value;
        private String name;

        DimensionTypeEnum(String value, String name) {
            this.value = value;
            this.name = name;
        }

        public String getValue() {
            return value;
        }

        public String getName() {
            return name;
        }

        /**
         * 通过value获取告警维度类型枚举
         */
        public static DimensionTypeEnum getEnumByValue(String value) {
            for (DimensionTypeEnum dimensionTypeEnum : DimensionTypeEnum.values()) {
                if (dimensionTypeEnum.value.equals(value)) {
                    return dimensionTypeEnum;
                }
            }
            return null;
        }

    }

    public enum redisEnum {
        map_path("alarm:custom_alarm:restore_alarm_map"),
        list_path("alarm:custom_alarm:restore_alarm_list"),
        obj_path("alarm:custom_alarm:restore_alarm_obj"),
        ;

        private String key;

        redisEnum(String key) {
            this.key = key;
        }

        public String getKey() {
            return key;
        }
    }


    /**
     * 业务告警的指标枚举
     * 原因：业务告警的指标是固定的并且查询字段的要求也是固定的。
     */
    public enum IndicatorEnum {
        businessFailRate("BS_FAIL_RATE_10", "业务失败率"),
        businessDealTimeRate("BS_FAIL_RATE_20", "业务处理时长告警率"),
        businessHealth("BS_FAIL_RATE_30", "业务健康度")
        ;
        /**
         * 指标编码
         * 数据库的指标编码必须与此一致
         */
        private String code;
        //指标名称
        private String name;

        IndicatorEnum(String code, String name) {
            this.code = code;
            this.name = name;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        /**
         * 根据指标编码返回指标枚举实体
         * @param code
         * @return
         */
        public static IndicatorEnum getEnumByCode(String code) {
            for (IndicatorEnum indicatorEnum : IndicatorEnum.values()) {
                if (indicatorEnum.code.equals(code)) {
                    return indicatorEnum;
                }
            }
            return null;
        }

    }
}
